package com.demo.controller;



import com.demo.annotation.GlobalInterceptor;
import com.demo.annotation.VerifyParam;
import com.demo.entity.dto.SessionUserLoginDto;
import com.demo.entity.enums.PermissionCodeEnum;
import com.demo.entity.po.DeviceApply;

import com.demo.entity.query.DeviceApplyQuery;

import com.demo.entity.vo.ResponseVO;


import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import com.demo.service.DeviceApplyService;


@RestController
@RequestMapping("/deviceApply")
public class DeviceApplyController extends ABaseController {

	@Resource
	private DeviceApplyService deviceApplyService;

	/**
	 * 分页查询
	 */
	@RequestMapping("/loadApplyList4Admin")
	@GlobalInterceptor(permissionCode = PermissionCodeEnum.DEVICE_APPLY_LIST)
	public ResponseVO loadDataList(DeviceApplyQuery query) {
		query.setOrderBy("apply_time desc");
		return getSuccessResponseVO(deviceApplyService.findListByPage(query));
	}


	/**
	 * 用户 查询申请列表
	 * @param session
	 * @param query
	 * @return
	 */
	@RequestMapping("/loadApplyList4User")
	@GlobalInterceptor(permissionCode = PermissionCodeEnum.MYAPPLY_LIST)
	public ResponseVO loadApplyList4User(HttpSession session,
										 DeviceApplyQuery query) {
		SessionUserLoginDto userLoginDto = getUserAdminFromSession(session);
		query.setUserId(userLoginDto.getUserId());
		query.setOrderBy("apply_time desc");
		return getSuccessResponseVO(deviceApplyService.findListByPage(query));
	}


	/**
	 * 新增
	 */
	@RequestMapping("/saveApply")
	@GlobalInterceptor
	public ResponseVO saveApply(HttpSession session,
								DeviceApply bean) {
		SessionUserLoginDto userLoginDto = getUserAdminFromSession(session);
		bean.setUserId(userLoginDto.getUserId());
		this.deviceApplyService.saveApply(bean);
		return getSuccessResponseVO(null);
	}


	/**
	 * 修改状态
	 */
	@RequestMapping("/updateStatus")
	@GlobalInterceptor(permissionCode = PermissionCodeEnum.DEVICE_APPLY_STATUS)
	public ResponseVO updateStatus(@VerifyParam(required = true) Integer applyId,
								   @VerifyParam(required = true) Integer status) {
		this.deviceApplyService.updateStatus(applyId,status);
		return getSuccessResponseVO(null);
	}

	/**
	 * 根据DeviceApplyId删除
	 */
	@RequestMapping("/delApply")
	@GlobalInterceptor(permissionCode = PermissionCodeEnum.DEVICE_APPLY_DEL)
	public ResponseVO deleteDeviceApplyByDeviceApplyId(@VerifyParam(required = true) Integer deviceApplyId) {
		this.deviceApplyService.deleteDeviceApplyByDeviceApplyId(deviceApplyId);
		return getSuccessResponseVO(null);
	}
}